<?php
class Application_Modules_Admin_Model_Frete
{
	public  function select($where = null, $order = null, $limit = null)
	{
		$dao = new Application_Model_DbTable_Frete();
		$select = $dao->select()->from($dao)->order($order)->limit($limit);
		if(!is_null($where)){
			$select->where($where);
		}
		return $dao->fetchAll($select)->toArray();
	}
	
	public function find($id)
	{
		$dao = new Application_Model_DbTable_Frete();
		$arr = $dao->find($id)->toArray();
		return $arr[0];
	}
	
	public function insert(array $request)
	{
		$dao = new Application_Model_DbTable_Frete();
		$dados = array(		
	         	'valor' => $request['valor_frete'],
	         	'pedagio' => $request['pedagio_frete'],
	         	'outros' => $request['outros_frete'],
	      		'seguro' => $request['seguro_frete'],
	      		'valor_total' => $request['valot_total_frete'],
	      		'icms' => $request['icms_frete'],
	      		'obs' => $request['obs_frete']
		);
		return $dao->insert($dados);
	}
	 
	public function  update(array  $request)
	{
		$dao = new Application_Model_DbTable_Frete();
		$dados = array(
	        	'valor' => $request['valor'],
	         	'pedagio' => $request['pedagio'],
	         	'outros' => $request['outros'],
	      		'seguro' => $request['seguro'],
	      		'valor_total' => $request['valor_total'],
	      		'icms' => $request['icms'],
	      		'obs' => $request['obs']
		);
		$where = $dao->getAdapter()->quoteInto("id_frete = ?", $request['id_frete']);
		$dao->update($dados, $where);
	}
	 
	public function delete($id)
	{
		$dao = new Application_Model_DbTable_Frete();
		$where = $dao->getAdapter()->quoteInto("id_frete = ?", $id);
		$dao->delete($where);
	}
}